#include "TBRwindowApplication.h"
using namespace TBR;
//#include <assert.h>
#include "TBRrendererDX11.h"
//class DX11Renderer;

WindowApplication::WindowApplication(const char* windowTitle, int xPos, int yPos, int w, int h, const TBR::ColorRGBA &backcolor)
:_windowTitle(windowTitle),
 _xPos(xPos),
 _yPos(yPos),
 _w(w),
 _h(h),
 _backcolor(backcolor)
{
		_renderer = new DX11Renderer(w, h);


}

WindowApplication* WindowApplication::create(const char* title, int xPos, int yPos, int w, int h, TBR::ColorRGBA backcolor)
{
	WindowApplication *winApp = new WindowApplication(title, xPos, yPos, w, h, backcolor);
	Application::TheApplication = winApp;


	return winApp;
	
}

WindowApplication::~WindowApplication()
{
	if(this->_renderer)
		_renderer->unInitialize();
	delete TheApplication;
}



int WindowApplication::run(int numArguments = 0, char** arguments = 0)
{
	return this->windowMain(numArguments, arguments);

}


//inline access / modifier
int WindowApplication::getxPos()
{
	return _xPos;
}

int WindowApplication::getyPos()
{
	return _yPos;
}

int WindowApplication::getWidth()
{
	return _w;
}

int WindowApplication::getHeight()
{
	return _h;
}

float WindowApplication::getAspectRatio()
{
	return _w/float(_h);
}

int WindowApplication::getWindowID()
{
	return _windowID;
}

void WindowApplication::setWindowID(int id)
{
	_windowID = id;
}

const char* WindowApplication::getWindowTitle()
{
	return _windowTitle;
}



// Call back functions

bool WindowApplication::onInitialize()
{
	_renderer->setWindowID(_windowID);
	//assert(_renderer->initialize());
	bool init = _renderer->initialize();
	return init;
}

void WindowApplication::onTerminate()
{
}

bool WindowApplication::onKeyDown(unsigned char key, int x, int y)
{
	return true;
}

bool WindowApplication::onMouseClick(int button, int state, int x, int y, unsigned int modifiers)
{
	return true;
}

void WindowApplication::onIdle()
{
	_renderer->draw();
}

void WindowApplication::onDisplay()
{
}



